﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fashion_API;

namespace A.Controller
{
    public class ProductCategoryController
    {
        public static List<ProductCategory> GetAllCategoryParent()
        {
            using (DALDataContext d = new DALDataContext())
            {
                return d.ProductCategories.Where(i => i.ParentId == null).OrderBy(i => i.OrderDisplay).ToList();
            }
        }

        public static List<ProductCategory> GetAllSubCategoryByParentId(object parentId)
        {
            using (DALDataContext d = new DALDataContext())
            {
                if (parentId == null)
                    return d.ProductCategories.Where(i => i.ParentId != null).OrderBy(i => i.ProductCategory1.OrderDisplay).ThenBy(i => i.OrderDisplay).ToList();
                else
                    return
                        d.ProductCategories.Where(i => i.ParentId == Convert.ToInt32(parentId)).OrderBy(
                            i => i.OrderDisplay).ToList();
            }
        }

        public static ProductCategory GetProductCategoryById(int id)
        {
            using (DALDataContext d = new DALDataContext())
            {
                return d.ProductCategories.FirstOrDefault(i => i.Id == id);
            }
        }
    }
}